<template>
  <div class="home-container fadeIn">
    <div class='home-content'>
      <div class='account'>
        <span>应用列表</span>
      </div>
      <div class="condition">
        <el-form ref="form" :inline="true" :model="form" class="demo-form-inline">
          <el-form-item label="appKey">
            <el-input v-model='form.appkey' placeholder='请输入appkey' type="text"  auto-complete='off' />
          </el-form-item>

          <el-form-item label="应用名称">
            <el-input v-model='form.appName' placeholder='请输入应用名称' type="text"  auto-complete='off' />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
            <el-button type="success" @click="add">添加</el-button>
            <!-- <el-button type="warning" @click="addAPK">直推APK申请</el-button> -->
          </el-form-item>
        </el-form>
      </div>
      <div class="tableList">
        <el-table
          :data="tableData"
          style="width: 100%"
          :default-sort = "{prop: 'date', order: 'descending'}"
          >
          <el-table-column
            prop="appkey"
            label="APPKEY">
          </el-table-column>
          <el-table-column
            prop="appName"
            label="应用名称">
          </el-table-column>
          <el-table-column
            label="应用类型">
            <template slot-scope="scope">
              <label>{{scope.row.appType===1?'游戏':'应用'}}</label>
            </template>
          </el-table-column>
          <el-table-column
            prop="appDescribe"
            label="应用描述"
            width="180">
          </el-table-column>
          <el-table-column
            prop="packageName"
            label="应用包名">
          </el-table-column>
          <el-table-column prop="configs" label="开关" width='150'>
            <template slot-scope="scope">
              <el-button size="mini" class="setting" type="success" @click="editSetting(im)" v-for='im in scope.row.configs'>{{im.appConfigName}}</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                @click="edit(scope.$index, scope.row)">编辑</el-button>
              <!-- <el-button
                size="mini"
                type="warning"
                @click="setting(scope.$index, scope.row)">设置</el-button>-->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="prev, pager, next"
          :total="1000">
        </el-pagination>
      </div>
    </div>
  </div>

</template>

<script>
import { mapState, mapActions } from 'vuex';
import { queryString } from '@/utils';

export default {
  name: 'HomeOperate',
  data() {
    return {
      form: {
        appkey: '',
        appName: '',
      },
      total: 0,
      tableData: [],
      checked: false,
    };
  },
  computed: {
    ...mapState('homeOperate', [
      'operateList',
    ]),
  },
  mounted() {
    this.setOperateList().then(() => {
      this.total = this.operateList.records;
      this.tableData = this.operateList.dataes;
    });
  },
  components: {
  },
  methods: {
    ...mapActions('homeOperate', [
      'setOperateList',
    ]),
    sousuo(num) {
      const data = {
        pageNo: num === 0 ? 1 : num,
        pageSize: 10,
        userId: this.$getLS('userId'),
        appkey: this.form.appkey,
        appName: this.form.appName,
      };
      this.setOperateList(queryString(data)).then(() => {
        this.total = this.operateList.records;
        this.tableData = this.operateList.dataes;
        this.pageNo = num === 0 ? 1 : num;
      });
    },
    onSubmit() {
      this.sousuo(0);
    },
    timeString(date) {
      const time = new Date(date);
      return `${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}`;
    },
    pageChange(val) {
      this.sousuo(val);
    },
    add() {
      this.$router.push({ path: '/main/HomeChild' });
    },
    addAPK() {
      this.$router.push({ path: '/main/HomeAPK' });
    },
    edit(index, row) {
      const data = queryString({
        appName: row.appName,
        appType: row.appType,
        appDescribe: row.appDescribe,
        packageName: row.packageName,
        userId: this.$getLS('userId'),
        id: row.id,
      });
      this.$router.push({ path: `/main/HomeChild?${data}` });
    },
    editSetting(row) {
      const data = queryString({
        appConfigName: row.appConfigName,
        appConfigValue: row.appConfigValue,
        configId: row.id,
      });
      this.$router.push({ path: `/main/HomeChildSetting?${data}` });
    },
    setting() {
      this.$router.push({ path: '/main/HomeSetting' });
    },
  },
};
</script>
<style media="screen">
.echarts {
height: 300px;
}
</style>
<style lang='scss' src='@/scss/pages/home_index.scss'/>
